<template>
  <div class="header">
    <div class="left-logo">
      <img src="@/assets/logo1.png" alt="logo" />
    </div>
    <div class="center">
      <img src="@/assets/master-modal.png" alt="">
    </div>
    <div class="right">
      <div class="maintainer-name">
        欢迎：<span>{{ getBaseInfo.nickname }}</span>
      </div>
      <!-- 头像 -->
      <el-dropdown>
        <span>
          <el-avatar :size="70" :src="getMAvatar" >
          </el-avatar>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>
            <p @click="$router.push('/maintainer/info')">
              <span class="iconfont">&#xe602;</span>
              <span> 个人中心</span>
            </p>
          </el-dropdown-item>
          <el-dropdown-item>
            <p @click="$router.push('/maintainer/orderlist')">
              <span class="iconfont">&#xe600;</span>
              <span> 维修订单</span>
            </p>
          </el-dropdown-item>
          <el-dropdown-item>
            <p @click="$router.push('/maintainer/takeorder')">
              <span class="iconfont">&#xe600;</span>
              <span> 去接单</span>
            </p>
          </el-dropdown-item>
          <el-dropdown-item v-if="$store.getters.getToken">
            <p @click="loginOut">
              <span class="iconfont">&#xe61f;</span>
              <span> 退出登录</span>
            </p>
          </el-dropdown-item>
          <el-dropdown-item v-else>
            <p @click="$router.push('/login')">
              <span class="iconfont">&#xe61f;</span>
              <span> 去登录</span>
            </p>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import { MessageBox, Message } from 'element-ui'
import { mapGetters } from 'vuex'

export default {
  data () { return {} },
  methods: {
    // 退出登录
    async loginOut () {
      await MessageBox.confirm('你确认要退出吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      await Message.success('退出成功')
      this.$store.commit('maintainerStore/setMaintainerInfo', {})
      this.$router.push('/login')
    }
  },
  computed: {
    ...mapGetters('maintainerStore', ['getMAvatar', 'getBaseInfo'])
  }
}
</script>

<style lang="less" scoped>
@bgcolor: #fff;
.header{
  padding: 20px 100px;
  background: @bgcolor;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left-logo{
    width: 200px;
    img{
      width: 100%;
      height: 100%;
    }
  }
  .right{
    // flex: 1;
    width: 20%;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    // background-color: pink;
    .maintainer-name{
      font-size: 18px;
      color: #333;
      span{
        font-size: 22px;
        font-weight: bold;
        color: #409EFF;
      }
    }
  }
}
</style>
